package com.info.zhiduoduo.repository.mapper.crowdsource;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.info.zhiduoduo.repository.dto.crowdsource.TaxPaymentVoucherListDto;
import com.info.zhiduoduo.repository.entity.crowdsource.TaxPaymentVoucher;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


public interface TaxPaymentVoucherMapper extends BaseMapper<TaxPaymentVoucher> {


    @Select("SELECT " +
            "tpv.* ,ts.tax_source_name,ccp.company_name " +
            "FROM " +
            "zdd_tax_payment_voucher tpv " +
            "LEFT JOIN zdd_tax_source ts ON ts.tax_source_id = tpv.tax_source_id " +
            "LEFT JOIN zdd_crowdsource_company_party ccp ON ccp.id = tpv.operating_entity_id " +
            "WHERE tpv.is_delete = 0 " +
            "AND IF(ISNULL(#{taxSourceId}) ,1=1,tpv.tax_source_id = #{taxSourceId}) " +
            "AND IF(ISNULL(#{operatingEntityId}) ,1=1,tpv.operating_entity_id = #{operatingEntityId}) " +
            "ORDER BY tpv.createtime DESC")
    List<TaxPaymentVoucherListDto> taxPaymentVoucherList(@Param("taxSourceId") Integer taxSourceId,
                                                         @Param("operatingEntityId") Integer operatingEntityId);


    @Select("SELECT " +
            "tpv.* ,ts.tax_source_name,ccp.company_name " +
            "FROM " +
            "zdd_tax_payment_voucher tpv " +
            "LEFT JOIN zdd_tax_source ts ON ts.tax_source_id = tpv.tax_source_id " +
            "LEFT JOIN zdd_crowdsource_company_party ccp ON ccp.id = tpv.operating_entity_id " +
            "WHERE tpv.is_delete = 0 " +
            "AND tpv.id = #{id} " +
            "ORDER BY tpv.createtime ")
    TaxPaymentVoucherListDto taxPaymentVoucherDetails(@Param("id") Integer id);

    @Select("SELECT tpv.*  " +
            "FROM zdd_tax_payment_voucher tpv " +
            "WHERE tpv.document_date = #{date} " +
            "AND tpv.tax_source_id = #{sourceId} " +
            "AND tpv.operating_entity_id = #{partyId} " +
            "AND tpv.is_delete = 0 ")
    List<TaxPaymentVoucher> taxSource(@Param("sourceId") Integer sourceId,@Param("date") String date,@Param("partyId") Integer partyId);

}
